package aplication;

import java.sql.*;

public class Conexion {
	private static Connection conexion;
	private static String bd="dswba_pl3_grupo4";
	private static String login="root";
	private static String password="";

	
	public void ConexionDAO(){		
	}
	
	public static void conectar(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conexion = DriverManager.getConnection("jdbc:mysql://localhost/?" + "user=" + login + "&password=" + password);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			System.out.println("Error al conectar a la base de datos");
			e.printStackTrace();
		}		
	}
	
	public static void conectar(String db){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conexion = DriverManager.getConnection("jdbc:mysql://localhost/" + db + "?" + "user=" + login + "&password=" + password);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			System.out.println("Error al conectar a la base de datos");
			e.printStackTrace();
		}		
	}
	
	public static Connection getConexion(){
		return conexion;
	}
	
	public static void cerrarConexion(){
		try {
			conexion.close();
		} catch (SQLException e) {
			System.out.println("No se pudo cerrar la conexion");
			e.printStackTrace();
		}
	}
}
